package xyz.sunne.crawler;


import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

import java.io.IOException;
import java.sql.*;
import java.util.List;

/**
 * @author Sunne
 * @version 1.0
 * @date 2021/10/12 0012
 */
public class myMovieMain {
    /**
     * 解析页面，并把数据插入至数据库
     */
    public static List<myMovie> getOnePage(String url, List<myMovie> movieList, HttpClient client) {
        try {
            movieList = URLHandle.urlParser(client, url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return movieList;
    }

    public static void main(String[] args) {
        /**
         * 初始化
         */
        List<myMovie> movieList = null;

        //生成客户端
        System.out.println("正在生成客户端...");
        HttpClient client = HttpClientBuilder.create().build();
        System.out.println("客户端生成完毕.");


        System.out.println("解析url...");
        //翻页爬取
        for(int i = 0; i < 10 ; i++) {
//            String offset = String.valueOf(i*10);//将i*10转换为字符串
            String url =  "https://haokan.baidu.com/v?vid=5700307353944701904";
            movieList = getOnePage(url,movieList,client);
        }
    }
}
